//
//  ViewController.m
//  UI_02homeworkNO2
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic,retain) UIImageView *animationImageView;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self creatImageView];
    [self creatAnimationImage];
    [self creatAnimationImageTwo];
    [self creatAnimationImageThree];
    [self creatFlower];
    [self creatGua];
    [self creatPlants];
    [self creatSlider];
}



-(void)creatImageView{
    UIImage *image = [UIImage imageNamed:@"BackGround.png"];
    
    UIImageView *backgroundImageView = [[UIImageView alloc]initWithImage:image];
    backgroundImageView.frame = self.view.frame;
    [self.view addSubview:backgroundImageView];
    [backgroundImageView release];
}


-(void)creatAnimationImage{
    
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Zombie0.tiff"]];
    animationImageView.frame = CGRectMake(200, 40, 200, 200);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:22];
    
    for (int i = 0; i <= 21; i ++) {
        NSString *name = [NSString stringWithFormat:@"Zombie%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
    
    }
    
    animationImageView.animationImages = mulArray;
    
//    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];
    
}

-(void)creatSlider{
    
    UISlider *siliderOne = [[UISlider alloc]initWithFrame:CGRectMake(50, 210, 200, 50)];
    siliderOne.value = 20;
    siliderOne.backgroundColor = [UIColor blackColor];
    [self.view addSubview:siliderOne];
    [siliderOne release];
    [siliderOne addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
}


-(void)sliderAction:(UISlider *)slider{
    
    slider.value = _animationImageView.animationDuration;
    
}




-(void)creatAnimationImageTwo{
    
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BZombie0.tiff"]];
    animationImageView.frame = CGRectMake(200, 430, 200, 200);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:25];
    
    for (int i = 1; i <= 25; i ++) {
        NSString *name = [NSString stringWithFormat:@"BZombie%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
        
    }
    
    animationImageView.animationImages = mulArray;
    
    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];
    
}


-(void)creatAnimationImageThree{
    
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BZombie0.tiff"]];
    animationImageView.frame = CGRectMake(200, 250, 200, 200);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:25];
    
    for (int i = 1; i <= 25; i ++) {
        NSString *name = [NSString stringWithFormat:@"BZombie%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
        
    }
    
    animationImageView.animationImages = mulArray;
    
    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];
    
}



-(void)creatFlower{
    
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"flower1.tiff"]];
    animationImageView.frame = CGRectMake(30, 430, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:19];
    
    for (int i = 1; i <= 18; i ++) {
        NSString *name = [NSString stringWithFormat:@"flower%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
        
    }
    
    animationImageView.animationImages = mulArray;
    
    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];
    
}

-(void)creatGua{
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"gua1.tiff"]];
    animationImageView.frame = CGRectMake(30, 100, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:17];
    
    for (int i = 1; i <= 16; i ++) {
        NSString *name = [NSString stringWithFormat:@"gua%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
        
    }
    
    animationImageView.animationImages = mulArray;
    
    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];

}


-(void)creatPlants{
    UIImageView *animationImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"plants1.tiff"]];
    animationImageView.frame = CGRectMake(30, 210, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    
    NSMutableArray *mulArray = [NSMutableArray arrayWithCapacity:10];
    
    for (int i = 1; i <= 9; i ++) {
        NSString *name = [NSString stringWithFormat:@"plants%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        
        [mulArray addObject:image];
        
    }
    
    animationImageView.animationImages = mulArray;
    
    animationImageView.animationDuration =2;
    
    [animationImageView startAnimating];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
